package com.gitee.ed.arithmetic.leetcode.question.question_1_100.question_1_10;

import com.gitee.ed.arithmetic.leetcode.SolutionRunner;
import com.gitee.ed.arithmetic.leetcode.common.Question;
import com.gitee.ed.arithmetic.leetcode.solution.solution_1_100.solution_1_10.Solution1;

/**
 * @author hongda.li
 */
public final class Question1 implements Question<Solution1> {
    @Override
    public String link() {
        return "https://leetcode.cn/problems/two-sum/description/";
    }

    @Override
    public String title() {
        return "1.两数之和";
    }

    @Override
    public String description() {
        return """
                给定一个整数数组 nums 和一个整数目标值 target，请你在该数组中找出 和为目标值 target  的那两个整数，并返回它们的数组下标。
                你可以假设每种输入只会对应一个答案。但是，数组中同一个元素在答案里不能重复出现。
                你可以按任意顺序返回答案。
                """;
    }

    @Override
    public void test(Solution1 solution) {
        this.test1(solution);

        this.test2(solution);

        this.test3(solution);
    }

    private void test1(Solution1 solution) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;

        int[] expect = {0, 1};
        int[] actual = solution.twoSum(nums, target);

        SolutionRunner.checkString(expect, actual);
    }

    private void test2(Solution1 solution) {
        int[] nums = {3, 2, 4};
        int target = 6;

        int[] expect = {1, 2};
        int[] actual = solution.twoSum(nums, target);

        SolutionRunner.checkString(expect, actual);
    }

    private void test3(Solution1 solution) {
        int[] nums = {3, 3};
        int target = 6;

        int[] expect = {0, 1};
        int[] actual = solution.twoSum(nums, target);

        SolutionRunner.checkString(expect, actual);
    }
}
